<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //定义一个源对象(目标对象)
        const obj={
            name:'张三'
        }
        const proxy=new Proxy(obj,{
            get(target,key,receiver){
                //当访问proxy代理对象的属性时，会执行get函数
                //将get函数的返回值作为表达式的值
                console.log('getting',target,key);
                return target[key]
            },
            set(target,key,value,receiver){
                //当设置proxy代理对象的属性时，会执行set函数
                console.log('setting',target,key,value);
                target[key]=value
                return true
            }
        })
        console.log('proxy.name',proxy.name)
        proxy.name='李四'
        console.log('obj',obj)
    </script>
</body>
</html>